<template>
  <div id="duty" v-loading="loading">
    <div class="notice-container" style="width: 34%">
      <div class="notice-title">
        <div>
          消息提醒：
          <span v-if="records.filter(d => d.state === 0).length">
            {{records.filter(d => d.state === 0).length}}条待处理消息
          </span>
          <span v-else>
            暂无最未处理消息
          </span>
        </div>
      </div>
      <div class="notice-item notice-msg" :key="r.id" v-for="r in records.filter(d => d.state === 0)">
        <div v-if="r.type === 0">
          请前往
          <div class="notice-item-attr" style="color: #409EFF;width: 50px">{{r.dtl.pRoomNo}}</div>
          监室将
          <div class="notice-item-attr" style="color: rgb(37,37,81);width: 200px">{{r.dtl.dbiName}}（{{r.dtl.prisoninNo}}）</div>
          带至
          <div class="notice-item-attr" style="color: teal;width: 40px">{{r.dtl.roomNo}}</div>
          房间
        </div>
        <div v-else-if="r.type === 1">
          请前往
          <div class="notice-item-attr" style="color: teal;width: 40px">{{r.dtl.roomNo}}</div>
          房间将
          <div class="notice-item-attr" style="color: rgb(37,37,81);width: 200px">{{r.dtl.dbiName}}（{{r.dtl.prisoninNo}}）</div>
          带回
          <div class="notice-item-attr" style="color: #409EFF;width: 50px">{{r.dtl.pRoomNo}}</div>
          监室
        </div>
        <div style="line-height: 36px">
          <el-button style="margin-right: 10px" size="mini" @click="handleRecord(r, 1)">处理</el-button>
        </div>
      </div>
    </div>
    <div class="notice-container" style="width: 32%">
      <div class="notice-title">
        <div>已带入</div>
      </div>
      <div class="notice-item" :key="r.id" v-for="r in records.filter(d => d.state === 1 && d.type === 0)">
        <div style="text-indent: 20px">
          <div class="notice-item-attr" style="width: 100px">
            监室：<span style="color: #409EFF;">{{r.dtl.pRoomNo}}</span>
          </div>
          <div class="notice-item-attr" style="width: 240px">
            对象：<span style="color: rgb(37,37,81);">{{r.dtl.dbiName}}（{{r.dtl.prisoninNo}}）</span>
          </div>
          <div class="notice-item-attr" style="width: 100px">
            房间：<span style="color: teal;">{{r.dtl.roomNo}}</span>
          </div>
          <div style="display: inline-block;text-indent: 0;margin-left: 20px;position: relative;top: -2px;">
            <el-tag v-if="records.some(d => d.type === 1 && d.state === 1 && d.irId === r.irId)" type="success">已带回</el-tag>
            <el-tag v-else type="danger">未带回</el-tag>
          </div>
        </div>
      </div>
    </div>
    <div class="notice-container" style="width: 30%">
      <div class="notice-title">
        <div>已带回</div>
      </div>
      <div class="notice-item" :key="r.id" v-for="r in records.filter(d => d.state === 1 && d.type === 1)">
        <div style="text-indent: 20px">
          <div class="notice-item-attr" style="width: 120px">
            监室：<span style="color: #409EFF;">{{r.dtl.pRoomNo}}</span>
          </div>
          <div class="notice-item-attr" style="width: 250px">
            对象：<span style="color: rgb(37,37,81);">{{r.dtl.dbiName}}（{{r.dtl.prisoninNo}}）</span>
          </div>
          <div class="notice-item-attr" style="width: 120px">
            房间：<span style="color: teal;">{{r.dtl.roomNo}}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Duty',
  data () {
    return {
      loading: false,
      records: []
    }
  },
  methods: {
    getRecords () {
      this.loading = true
      this.$http.POST('Interviewer:getBringRecords', {}).then(res => {
        if (res.data.code === 200) {
          if (res.data.rows.length) {
            this.$http.POST('Interviewer:getInfosBuIrIds', null, { ids: res.data.rows.map(d => d.irId).join(',') }).then(res1 => {
              const records = res.data.rows
              records.forEach(r => {
                r.dtl = res1.data.data.find(r1 => r1.irId === r.irId)
              })
              console.log(records)
              this.$set(this, 'records', records)
            })
          }
          this.loading = false
        } else {
          this.$alert(res.data.msg, '提示', {
            confirmButtonText: '确定',
            callback: () => {
              this.$router.push('/login')
            }
          })
        }
      })
    },
    handleRecord (record, state) {
      this.$confirm('确认手动处理该条消息？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        this.$http.POST('Interviewer:editBringRecords', {
          id: record.id,
          state
        }).then(res => {
          if (res.data.code === 200) {
            this.$message({
              message: '处理成功',
              type: 'success'
            })
            this.getRecords()
          }
        })
      })
    }
  },
  created () {
    this.getRecords()
    this.$ws.CreateEvent('duty', e => {
      const msg = JSON.parse(e.data)
      if (msg.code === this.MESSAGE_CODE.RELAY) {
        return
      }
      if (msg.msgType === 'new-record') {
        this.getRecords()
      }
    })
  }
}
</script>

<style scoped>
  * {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    margin: 0;
    padding: 0;
  }
  #duty{
    width: 100%;
    height: 100%;
    background-image: url("../assets/Arraign/img/bg.png");
    background-size: 100% 100%;
    display: flex;
    justify-content: space-around;
  }
  .notice-container{
    height:750px;
    margin-top: 100px;
    border: 1px solid rgb(37,37,81);
    border-radius: 5px;
    background-color: #fff;
    overflow: auto;
  }
  .notice-item{
    line-height: 40px;
    width: calc(100% - 40px);
    border: 1px solid #aaa;
    background-color: #fff;
    border-radius: 5px;
    color: red;
    font-size: 18px;
    margin-top: 20px;
    margin-left: 20px;
    position: relative;
    overflow: hidden;
  }
  .notice-item:nth-of-type(1){
    margin-top: 10px;
  }
  .notice-item-attr{
    display: inline-block;
    text-align: center;
    text-indent: 0;
  }
  .notice-item.notice-msg{
    cursor: pointer;
    display: flex;
    justify-content: space-around;
    transition: all .2s;
  }
  .notice-item.notice-msg:hover{
    background-color: #eee;
  }
  .notice-title{
    width: 100%;
    text-align: left;
    text-indent: 10px;
    line-height: 40px;
    background-color: rgb(37,37,81);
    color: #eee;
    font-size: 18px;
  }
  *::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }

  *::-webkit-scrollbar-thumb {
    background-color: rgba(199, 239, 252, .2);
    height: 20px;
    outline-offset: -2px;
    outline: 1px solid #999;
    -webkit-border-radius: 4px;
    border: 1px solid #999
  }
</style>
